import os
from configparser import ConfigParser

from cn.boz.utils.Constants import Constants

class ProjectUtils:

    @staticmethod
    def getProjectPath():
        """
        获取项目路径
        :return:
        """
        abspath=os.path.abspath(__file__)
        return abspath[:abspath.index("%s/"%(Constants.PROJECT_NAME))+len("%s/"%(Constants.PROJECT_NAME))]
        pass


    @staticmethod
    def getResourcePath():
        """
        获取资源路径
        :return:
        """
        return os.path.join(ProjectUtils.getProjectPath(),Constants.RESOURCE)
        pass

    @staticmethod
    def getConfigPath():
        """
        获取配置路径
        :return:
        """
        return os.path.join(ProjectUtils.getProjectPath(), Constants.CONFIG)
        pass

    @staticmethod
    def getTemporyPath():
        """
        获取临时路径
        :return:
        """
        return os.path.join(ProjectUtils.getProjectPath(), Constants.TEMP)
        pass

    @staticmethod
    def getConfigFilePath():
        """
        获取配置文件路径
        :return:
        """
        return os.path.join(ProjectUtils.getConfigPath(), Constants.CONFIG_FILE)
        pass

    @staticmethod
    def getLogPath():
        """
        获取日志文件路径
        :return:
        """
        return os.path.join(ProjectUtils.getConfigPath(), Constants.LOG_PATH)
        pass

    @staticmethod
    def getConfigSessionValue(session,key):
        """
        获取配置指定的session中的值
        :param session: 区块
        :param key: 键
        :return:
        """
        cfg: ConfigParser = ConfigParser()
        abspath = ProjectUtils.getConfigFilePath()
        cfg.read(abspath)
        return  cfg.get(session, key)

